home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / misc / emu / arosdev.lha / AROS / rom / utility / allocnamedobjecta.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  5KB  |  186 lines

  1. /*
  2.     $Id: allocnamedobjecta.c,v 1.3 1997/01/27 13:17:13 digulla Exp $
  3.     $Log: allocnamedobjecta.c,v $
  4.     Revision 1.3  1997/01/27 13:17:13  digulla
  5.     Added #include <proto/exec.h>
  6.  
  7.     Revision 1.2  1997/01/27 00:32:29  ldp
  8.     Polish
  9.  
  10.     Revision 1.1  1996/12/18 01:27:35  iaint
  11.     NamedObjects
  12.  
  13.     Desc: AllocNamedObject() - allocate a NamedObject.
  14.     Lang: english
  15. */
  16. #include <proto/exec.h>
  17. #include "utility_intern.h"
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22. #include <proto/utility.h>
  23.  
  24.     AROS_LH2(struct NamedObject *, AllocNamedObjectA,
  25.  
  26. /*  SYNOPSIS */
  27.     AROS_LHA(STRPTR          , name, A0),
  28.     AROS_LHA(struct TagItem *, tagList, A1),
  29.  
  30. /*  LOCATION */
  31.     struct UtilityBase *, UtilityBase, 38, Utility)
  32.  
  33. /*  FUNCTION
  34.     Allocate a new NamedObject and initializes it as requested.
  35.     This object can then be used as an object in a name space.
  36.     Optionally you give this object a name space, and use it to
  37.     nest name spaces. You can also allocate some memory which is
  38.     attached to this object for your own personal use.
  39.  
  40.     When the object is allocated, it will automatically have one user.
  41.     To allow other users to remove this object from a namespace, you
  42.     must call ReleaseNamedObject() on this object.
  43.  
  44.     INPUTS
  45.     name    -   The name of the NamedObject. Obviously this MUST be
  46.             specified (otherwise it wouldn't be named would it?)
  47.     tagList -   A TagList containing some extra information for this
  48.             NamedObject. These are:
  49.  
  50.             ANO_NameSpace: Allocate a NameSpace for this
  51.             NamedObject. This will allow you to link other
  52.             NamedObjects into a group. You cannot add a
  53.             NamedObject with a NameSpace to another NameSpace.
  54.             Boolean, default is FALSE.
  55.  
  56.             ANO_UserSpace: This tag says that you want extra memory
  57.             allocated for a UserSpace. The ti_Data field of
  58.             this TagItem contains the amount of memory to
  59.             allocate. Specifying this Tag with a ti_Data of 0,
  60.             is equivalent to the default, which is no UserSpace.
  61.             The UserSpace address can be found in the no_Object
  62.             field of the NamedObject structure.
  63.  
  64.             ANO_Priority: This is the List priority of the
  65.             NamedObject and should be a signed BYTE value
  66.             between -128 and 127. This is taken into account
  67.             in adding and finding NamedObjects, as the highest
  68.             priority NamedObject will be returned first. The
  69.             default value is 0.
  70.  
  71.             ANO_Flags: This allows you to initialize the value of
  72.             the NameSpace flags which control certain aspects
  73.             of the NameSpace. See the file utility/name.h.
  74.  
  75.     RESULT
  76.     A pointer to a new NamedObject, or NULL if the allocation failed
  77.     due to no free memory.
  78.  
  79.     NOTES
  80.  
  81.     EXAMPLE
  82.  
  83.     BUGS
  84.  
  85.     SEE ALSO
  86.     utility/name.h, FreeNamedObject(), Utility: Named Objects
  87.  
  88.     INTERNALS
  89.  
  90.     HISTORY
  91.     29-10-95    digulla automatically created from
  92.                 utility_lib.fd and clib/utility_protos.h
  93.     11-08-96    iaint   Reworked for AROS.
  94.     08-10-96    iaint   Changed to three memory areas after discussion
  95.                 in AROS-DEV today.
  96.     18-10-96    iaint   Completely rewrote.
  97.  
  98. *****************************************************************************/
  99. {
  100.     AROS_LIBFUNC_INIT
  101.  
  102.     struct IntNamedObject    *no  = NULL;
  103.     /*
  104.     This is the size of the required sections of the NamedObject.
  105.     */
  106.     LONG            size = 0;
  107.  
  108.     if(name)
  109.     {
  110.     /* Allocate the actual object, by def'n these are public */
  111.     no = AllocMem(sizeof(struct IntNamedObject), MEMF_CLEAR|MEMF_PUBLIC);
  112.  
  113.     if(no == NULL)
  114.     {
  115.         return NULL;
  116.     }
  117.  
  118.     no->no_Node.ln_Name = AllocVec(strlen(name) + 1, MEMF_CLEAR|MEMF_PUBLIC);
  119.     if(no->no_Node.ln_Name != NULL)
  120.     {
  121.         strcpy(no->no_Node.ln_Name, name);
  122.     }
  123.     else
  124.     {
  125.         FreeVec(no);
  126.         return NULL;
  127.     }
  128.  
  129.     no->no_Node.ln_Pri = GetTagData( ANO_Priority, 0, tagList );
  130.     no->no_UseCount = 0;
  131.     no->no_FreeObject = FALSE;
  132.  
  133.     /* Find out if we need a NameSpace. */
  134.     if(GetTagData(ANO_NameSpace, FALSE, tagList))
  135.     {
  136.         no->no_NameSpace = AllocMem(sizeof(struct NameSpace), MEMF_CLEAR|MEMF_PUBLIC);
  137.         if(no->no_NameSpace != NULL)
  138.         {
  139.         no->no_NameSpace->ns_Flags = GetTagData(ANO_Flags, 0, tagList);
  140.         InitSemaphore(&no->no_NameSpace->ns_Lock);
  141.         NewList((struct List *)&no->no_NameSpace->ns_List);
  142.         }
  143.         else
  144.         {
  145.         FreeNamedObject(GetNamedObject(no));
  146.         return FALSE;
  147.         }
  148.     }
  149.  
  150.     /* Set up the UserSpace. Maybe in the future we will be able to
  151.        have a UserSpace who has a different memory type to the
  152.        NamedObject.
  153.     */
  154.  
  155.     if((size = GetTagData(ANO_UserSpace, 0, tagList)))
  156.     {
  157.         GetNamedObject(no)->no_Object = AllocVec(size, MEMF_CLEAR|MEMF_PUBLIC);
  158.         if(no->no.no_Object == NULL)
  159.         {
  160.         FreeNamedObject(GetNamedObject(no));
  161.         return NULL;
  162.         }
  163.         else
  164.         {
  165.         /* We should free the object in FreeNamedObject(). */
  166.         no->no_FreeObject = TRUE;
  167.         }
  168.     }
  169.     else
  170.     {
  171.         /* Don't free the object, we didn't allocate it. */
  172.         no->no_FreeObject = FALSE;
  173.         GetNamedObject(no)->no_Object = NULL;
  174.     }
  175.  
  176.     no->no_UseCount = 1;
  177.     return GetNamedObject(no);
  178.  
  179.     } /* if ( name ) */
  180.  
  181.     return NULL;
  182.  
  183.     AROS_LIBFUNC_EXIT
  184.  
  185. } /* AllocNamedObjectA */
  186.